<template>
  <THeader title="审批详情">
  </THeader>
  <div v-show="flag">
    <div v-for="(applys,index) in applyInfo" :key="index" style="margin-bottom: 5vw">
      <van-cell-group inset style="margin-top:5vw" v-for="(applyI,indexI) in applys.sources" :key="indexI">
        <van-cell>
          <van-row style="border-left: 1vw solid #1989fa;padding: 0 1vw">
            <van-col span="19" style="overflow: hidden;text-overflow: ellipsis; white-space: nowrap;">
              <span style="font-size: 4vw;">{{ applys.course }}</span>
            </van-col>
            <van-col span="5">
              <span style="font-size: 3.5vw;color:#9a9b9d">上课信息</span>
            </van-col>
          </van-row>
        </van-cell>
        <van-cell style="font-size: 3.5vw">
          <van-row style="color: #969799;">
            <van-col span="8">{{ getDay(applyI) }}</van-col>
            <van-col span="8">{{ getPart(applyI) }}</van-col>
            <van-col span="8">{{ getWeek(applyI) }}</van-col>
          </van-row>
          <van-row style="color: #969799;padding-top: 1rem">
            <van-col span="3">
              班级
            </van-col>
            <van-col offset="2">
              {{ applys.classes }}
            </van-col>
          </van-row>
        </van-cell>
      </van-cell-group>
    </div>

    <van-cell-group inset style="margin-bottom: 5vw">
      <van-cell>
        <van-row>
          <van-col span="5" style="color:#4b4c4d;">申请理由</van-col>
          <van-col offset=2 span="16">{{ reason }}</van-col>
        </van-row>
      </van-cell>
    </van-cell-group>
    <van-cell-group inset>
      <van-field
          v-model="message"
          rows="2"
          autosize

          label="审批意见"
          type="textarea"
          maxlength="50"
          placeholder="请输入意见"
          required
          show-word-limit
      />
    </van-cell-group>
    <van-button round block color="#1989fa" class="btu" @click="succeed" style="margin-top: 8vw">同意</van-button>
    <van-button round block plain hairline type="primary" class="btu" @click="failed">不同意</van-button>
  </div>

</template>

<script setup>
import {useRoute, useRouter} from "vue-router/dist/vue-router";
import {getAdjustRecordById} from "/@/api/ttsp";
import {AuditRecord} from "/@/api/ttsp";
import {Toast} from "vant";

const router = new useRouter()
const route = useRoute()
const id = route.query.id
const reason = route.query.reason

const applyInfo = ref([])
const message = ref("")
const flag = ref(false)
const initData = async () => {
  // flag.value=false
  const res = await getAdjustRecordById(id)
  applyInfo.value = res.response.value.extend.records
  if (applyInfo.value) {
    flag.value = true
    console.log("apply", applyInfo.value)
  }
}
const getDay = (value) => {
  return value.split(" ")[0]
}
const getPart = (value) => {
  return value.split(" ")[2]
}
const getWeek = (value) => {
  return value.split(" ")[3]
}
const adMessage = () => {
  console.log("message", message.value.length)
  if (message.value.length < 3) {
    return 0
  }
  return 1
}
const goBack = () => {
  router.back()
}
const succeed = async () => {
  //1同意
  const m = adMessage()
  if (!m) {
    Toast("意见不能少于3个字")
  } else {
    const res = await AuditRecord(id, "1", message.value)
    const result = res.response.value.msg
    console.log(result)
    Toast(result)
    setTimeout(goBack(), 500)
  }
}
const failed = async () => {
  //3不同意
  const m = adMessage()
  if (!m) {
    Toast("意见不能少于3个字")
  } else {
    const res = await AuditRecord(id, "3", message.value)
    const result = res.response.value.msg
    console.log(result)
    Toast(result)
    setTimeout(goBack(), 500)
  }

}
onMounted(() => {
  initData();
})
</script>

<style scoped>
.btu {
  margin-top: 6vw;
  width: 80%;
  margin-left: 10%
}

</style>
